package network.udp;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;

/**
 * @author mubei
 * @date 2021/12/5
 * @description   不需要连接服务器
 *
 */
public class UDPClient_ {


    public static void main(String[] args) throws Exception {
        // 建立socket
        DatagramSocket socket = new DatagramSocket();

        // 建立包
        String msg = "真不错";
        InetAddress localhost = InetAddress.getByName("localhost");
        int port = 9999;
        /*
        * 数据
        * 长度
        * ip地址
        * 端口号
        * */
        DatagramPacket packet = new DatagramPacket(msg.getBytes(), 0, msg.getBytes().length, localhost, port);

        // 发送包
        socket.send(packet);

        socket.close();
    }
}
